package com.zhao.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

//一定不要忘记把处理器添加到IOC容器中
//这些策略要想被识别，就丢到Springboot里面
@Component
//添加日志
@Slf4j
public class MyMMetaObjectHandler implements MetaObjectHandler {
    //插入时候的填充策略
    @Override
    public void insertFill(MetaObject metaObject) {

        log.info("start insert .....");
        this.setFieldValByName("createTime",new Date(),metaObject);
        this.setFieldValByName("updateTime",new Date(),metaObject);

    }
    //更新时候的填充策略
    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("start update info......");
        this.setFieldValByName("updateTime",new Date(),metaObject);
    }
}
